package homework13;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.management.BufferPoolMXBean;
import java.util.HashMap;
import java.util.Iterator;

/**
 * @author Administrator
 */
public class Task1 {
    public static void main(String[] args) throws IOException {
        HashMap<Integer,String> hashMap=new HashMap<Integer,String>();
        hashMap.put(1,"哈希");
        hashMap.put(2,"按时");
        hashMap.put(3,"王热");
        hashMap.put(4,"爱你如");
        hashMap.put(5,"云雾山");

        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("D:\\abc.txt"));

        Iterator iterator=(Iterator) hashMap.keySet().iterator();
        while (iterator.hasNext()){
            //获取每一个键　
            Integer key=(Integer) iterator.next();
            //根据键得到值　
            String Value=hashMap.get(key);
            //把键和值写入文件
            bufferedWriter.write(key+"--"+Value);
            bufferedWriter.newLine();
            bufferedWriter.flush();

        }
        bufferedWriter.close();
    }
}
